import javax.swing.*;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableModel;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.Collection;
import java.util.LinkedList;

public class FilmData {
	private String name,
			type,
			actor;
	private double avgRating;
	private int rating_num;
	private int year;

	public FilmData() {
	}

	public FilmData(
			String name, String type, String actor,
			double avgRating, int rating_num, int year) {
		this.name = name;
		this.type = type;
		this.actor = actor;
		this.avgRating = avgRating;
		this.rating_num = rating_num;
		this.year = year;
	}

	public String getName() {
		return name;
	}

	public String getType() {
		return type;
	}

	public String getActor() {
		return actor;
	}

	public double getAvgRating() {
		return avgRating;
	}

	public int getRating_num() {
		return rating_num;
	}

	public int getYear() {
		return year;
	}
	public String[] toStrArray(){
		return new String[]{
				name,type,actor,
				String.valueOf(avgRating),
				String.valueOf(rating_num),
				String.valueOf(year)
		};
	}


}
class MyTable extends JTable{
	MyTable(LinkedList<FilmData> data, String[] title){
		if(data.isEmpty())
			throw new NullPointerException();
		DefaultTableModel model=new DefaultTableModel(new String[][]
				{data.removeFirst().toStrArray()},title);
		MyTable table=new MyTable(model);
		while (!data.isEmpty()){
			model.addRow(data.removeFirst().toStrArray());
		}
		table.addMouseListener(new TableListener());
	}
	class TableListener extends MouseAdapter{
		@Override
		public void mouseClicked(MouseEvent e) {
			JOptionPane.showInputDialog("请输入"+MyTable.this.getColumnName(1));
		}
	}
	public MyTable(TableModel dm) {
		super(dm);
	}
}